// customController project customController.go
package controllers

import (
	"github.com/revel/revel"
	"io/ioutil"
	"time"
)

type Controller struct {
	*revel.Controller
	t    time.Time
	body []byte
}

func (c *Controller) RenderResult(obj interface{}) revel.Result {
	return c.RenderJson(wrap(c.Request.Locale, obj))
}

func (c *Controller) StartAction() revel.Result {
	defer c.Request.Body.Close()
	c.body, _ = ioutil.ReadAll(c.Request.Body)
	c.t = time.Now()

	revel.INFO.Printf("Begin request %s: %s from:%s",
		c.Request.RequestURI, c.body, c.Request.RemoteAddr)
	return nil
}

func (c *Controller) EndAction() revel.Result {
	revel.INFO.Printf("End respose %s: %+v used:%v",
		c.Request.RequestURI, c.Result, time.Since(c.t))
	return nil
}

func init() {
	revel.InterceptMethod((*Controller).StartAction, revel.BEFORE)
	revel.InterceptMethod((*Controller).EndAction, revel.AFTER)
}
